package org.springcloud.wisdom.spring_02_classroom.student.attendence.controller;

import org.springcloud.wisdom.spring_02_classroom.bean.BaseController;
import org.springcloud.wisdom.spring_02_classroom.bean.ResponseData;
import org.springcloud.wisdom.spring_02_classroom.student.attendence.service.AttendenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/attendence")
public class AttendenceController extends BaseController {

    @Autowired
    private AttendenceService attendenceService;

    //学生查看考勤表
    @GetMapping("/look")
    public ResponseData<Object> attendenceBySidAndCid(String sid  ) {
        return returnObject(attendenceService.attendenceBySidAndCid(sid));
    }

    //教师查看考勤表
    @RequestMapping("/all")
    public ResponseData<Object> getPage(@RequestParam("pageNum") int pageNum,
                                        @RequestParam("pageSize") int pageSize,
                                        @RequestParam(value = "cid", required = false) String cid,
                                        @RequestParam(value = "sname", required = false) String sname) {
        if (cid == null || cid.isEmpty()) {
            return new ResponseData<>(400, "CID参数不能为空", null);
        }
        return returnObject(attendenceService.AllAttendence(pageNum, pageSize, cid,sname));
    }
}
